package com.jiang.jixiang.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.NonNull;

import com.jiang.jixiang.R;
import com.ws.universal.tools.wsui.widget.QMUIRoundButton;


/**
 * @创建者 ws
 * @创建时间 2021/11/2
 * @描述
 */
public class InputDialog extends Dialog {
    private Context mContext;
    private EditText edInput;
    private QMUIRoundButton btnSubmit;

    private OnDiaogClickListener mListener;

    public InputDialog(@NonNull Context context) {
        super(context, R.style.dialog_alarm);
        mContext = context.getApplicationContext();
        initUI();
    }


    public void setBtnListener(OnClickListener lListener) {
        btnSubmit.setTag(lListener);
        btnSubmit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                OnClickListener lListener = (OnClickListener) btnSubmit.getTag();
                lListener.onClick(InputDialog.this, 0);
            }
        });
    }


    public String getInput() {
        return edInput.getText().toString().trim();
    }


    private void initUI() {
        View dlgView = LayoutInflater.from(mContext).inflate(R.layout.dialog_input, null);

        edInput = dlgView.findViewById(R.id.edInput);
        btnSubmit = dlgView.findViewById(R.id.btnSubmit);
        btnSubmit.setChangeAlphaWhenPress(true);
        OnClickListener listener = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int arg1) {
                if (mListener != null) {
                    mListener.onClick(arg1);
                }
                dialog.dismiss();
            }
        };
        setBtnListener(listener);
        setContentView(dlgView);
        setCanceledOnTouch(true);


    }


    public void setCanceledOnTouch(boolean isCanceledOnTouch) {

        setCanceledOnTouchOutside(isCanceledOnTouch);
    }


    public interface OnDiaogClickListener {
        void onClick(int which);
    }
}
